import 'dart:math';

import 'package:flutter/material.dart';

List<Color> colors = [Colors.yellow, Colors.white];

class SrtTransform {
  static List<SrtModel> getList(List<String> strings) {
    List<SrtModel> list = [];

    List<String> timeList = [];
    List<String> contentList = [];

    for (int i = 0; i < strings.length; i++) {
      if (i % 4 == 1) {
        timeList.add(strings[i]);
      }
      if (i % 4 == 2) {
        contentList.add(strings[i]);
      }
    }

    for (int y = 0; y < timeList.length; y++) {
      String str = timeList[y];

      List<String> strL = str.split("-->");

      DateTime start = DateTime.parse("1970-01-01 " + strL.first.trim())
          .add(Duration(hours: 8));
      DateTime end = DateTime.parse("1970-01-01 " + strL.last.trim())
          .add(Duration(hours: 8));

      print("Start:" + start.millisecondsSinceEpoch.toString());
      print("end:" + end.millisecondsSinceEpoch.toString());

      SrtModel srtModel = SrtModel(
          startTime: (start.millisecondsSinceEpoch).floor(),
          endTime: (end.millisecondsSinceEpoch).floor(),
          content: contentList[y],
          fontSize: (18 - y % 4),
          color: colors[y % 2]);

      list.add(srtModel);
    }

    return list;
  }
}

class SrtModel {
  int? startTime;
  int? endTime;
  String? content;

  Color color;
  double fontSize;

  SrtModel({
    this.startTime,
    this.endTime,
    this.content,
    required this.color,
    required this.fontSize,
  });

  @override
  String toString() {
    return 'SrtModel{startTime: $startTime, endTime: $endTime, content: $content}';
  }
}
